const express = require('express');
const db = require('../utils/db.js')
const router = express.Router()
// 根据选择的堂食/外送/商城订单获取列表
router.get('/list', (req, res) => {
  const typeidSql = `SELECT id FROM type WHERE typeName = '${req.query.active}';`
  let order = '`' + 'order' + '`'
  db.query(typeidSql, (err, data) => {
    if (err == null) {
      let typeid = data[0].id;
      let sql =
        `SELECT * FROM  ${order} o,menu m,ordermenu om WHERE type_id=${typeid} and o.id=om.order_id and m.id=om.menu_id;`;
      db.query(sql, (err2, data2) => {
        if (err == null) {
          res.send({
            data2,
            msg: '获取成功'
          })
        } else {
          res.send({
            msg: err2
          })
        }
      })
    } else {
      res.send({
        msg: err
      })
    }
  })
})



module.exports = router;
